package com.gable.report.util;

import com.alibaba.fastjson.JSON;
import com.gable.report.common.init.InitUtil;
import com.gable.report.common.util.ChineseToEnglish;
import com.gable.report.common.util.Page;
import com.gable.report.model.ChartsAreaQuery;
import com.gable.report.model.ChartsHospitalQuery;
import com.gable.report.model.ChartsPriceCategory;
import com.gable.report.model.ChartsSearchView;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;

/**
 * Created by lvdouStart on 2017/7/19.
 * 报表工具类
 * 2017-9-27 默认起始金额为0的情况，参数改为null,统计金额为null的设备
 */
public class ChartsUtil {

    /**
     * 处理结果为null的值
     * @param object
     * @return
     * @throws Exception
     */
    public static Object handleNull(Object object)throws Exception{
        if(object == null){
            return null;
        }
        Class clazz = object.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for(int i=0;i<fields.length;i++){
            Method get = getGetMethod(clazz,fields[i].getName());
            Method set = getSetMethod(clazz,fields[i].getName());
            Object resultObject = get.invoke(object);
            if(resultObject == null && "java.lang.Long".equals(fields[i].getType().getName())){
                set.invoke(object,new Object[]{0L});
            }else if(resultObject == null && "java.lang.Double".equals(fields[i].getType().getName())){
                set.invoke(object,new Object[]{0.0});
            }else if(resultObject == null && "java.lang.Integer".equals(fields[i].getType().getName())){
                set.invoke(object,new Object[]{0});
            }

       }
        return object;
    }

    /** 
     * @Author: 杨青桦
     * @Description: 获取对应医院/区域的金额区间及对应名称
     * @Date: 2017/9/8 12:01
     * @param chartsPriceCategory
     * @return
     */
    public static Map<String,Object> getDevicePriceCategoryName(ChartsPriceCategory chartsPriceCategory){
        Map returnMap = new HashMap();
        String priceCategoryName = ">=" + chartsPriceCategory.getPriceMax()/1000000 + "万";
        String priceCategoryName2 = chartsPriceCategory.getPriceMin()/1000000 + "万-" + chartsPriceCategory.getPriceMax()/1000000 + "万";
        String priceCategoryName3 = "<" + chartsPriceCategory.getPriceMin()/1000000 + "万";
        StringBuffer sb = new StringBuffer();
        sb.append("case when a.price >= " + chartsPriceCategory.getPriceMax() + " then '");
        sb.append(priceCategoryName);
        sb.append("' when a.price >= " + chartsPriceCategory.getPriceMin() + " and a.price < " + chartsPriceCategory.getPriceMax() + " then '");
        sb.append(priceCategoryName2);
        sb.append("' when a.price < " + chartsPriceCategory.getPriceMin() + " then '");
        sb.append(priceCategoryName3);
        sb.append("' else '无' end");
        returnMap.put("priceCategory",Arrays.asList(priceCategoryName,priceCategoryName2,priceCategoryName3));
        returnMap.put("asName",sb.toString());
        return returnMap;
    }


    /**
     * @Author: 杨青桦
     * @Description: 获取对应医院/区域的年限指数区间及对应名称
     * @Date: 2017/9/8 12:01
     * @param chartsPriceCategory
     * @return
     */
    public static Map<String,Object> getAgeLimitCategoryName(ChartsPriceCategory chartsPriceCategory){
        Map returnMap = new HashMap();
        String AgeLimitCategoryNameName =  "1.0";
        String AgeLimitCategoryNameName2 = "0.7" + "-" + "1.0";
        String AgeLimitCategoryNameName3 = "0.7";
        StringBuffer sb = new StringBuffer();
        sb.append("case when a.cur_age_limit_measure >= " + "1.0" + " then '");
        sb.append(AgeLimitCategoryNameName);
        sb.append("' when a.cur_age_limit_measure >= " + "0.7" + " and a.cur_age_limit_measure < " + "1.0" + " then '");
        sb.append(AgeLimitCategoryNameName2);
        sb.append("' when a.cur_age_limit_measure < " + "0.7" + " then '");
        sb.append(AgeLimitCategoryNameName3);
        sb.append("' else '无' end");
        returnMap.put("ageLimitCategory",Arrays.asList(AgeLimitCategoryNameName,AgeLimitCategoryNameName2,AgeLimitCategoryNameName3));
        returnMap.put("asNameCur",sb.toString());
        sb.setLength(0);
        sb.append("case when b.last_age_limit_measure >= " + "1.0" + " then '");
        sb.append(AgeLimitCategoryNameName);
        sb.append("' when b.last_age_limit_measure >= " + "0.7" + " and b.last_age_limit_measure < " + "1.0" + " then '");
        sb.append(AgeLimitCategoryNameName2);
        sb.append("' when b.last_age_limit_measure < " + "0.7" + " then '");
        sb.append(AgeLimitCategoryNameName3);
        sb.append("' else '无' end");
        returnMap.put("asNameLast",sb.toString());
        return returnMap;
    }

    /**
     * @Author: 杨青桦
     * @Description: 批量处理空值
     * @Date: 2017/7/19 11:25
     * @param list
     * @return
     * @throws Exception
     */
    public static List handleNull(List list) throws Exception{
        for(Object obj : list){
            handleNull(obj);
        }
        return list;
    }

    /** 
     * @Author: 杨青桦
     * @Description:  处理设置政府报表sql参数
     * @Date: 2017/7/19 11:32
     * @param chartsAreaQuery
     * @return
     */
    public static Map<String,Object> getParamMap(Long areaId,ChartsAreaQuery chartsAreaQuery) throws Exception{
        Map<String,Object> map = new HashMap<>();
        handleString(chartsAreaQuery);
        if(chartsAreaQuery.getEnableYearStart() != null){
            chartsAreaQuery.setEnableYearStart(chartsAreaQuery.getEnableYearStart()+"-1-1");
        }
        if(chartsAreaQuery.getEnableYearEnd() != null){
            Integer year = Integer.valueOf(chartsAreaQuery.getEnableYearEnd())+1;
            chartsAreaQuery.setEnableYearEnd(year+"-1-1");
        }
        List<Long> hospitalIds = JSON.parseArray(chartsAreaQuery.getHospitalId(),Long.class);
        List<Long> hospitalLevelIds = JSON.parseArray(chartsAreaQuery.getLevelId(),Long.class);
        List<Long> riskIds = JSON.parseArray(chartsAreaQuery.getRiskId(),Long.class);
        List<Long> typeIds = JSON.parseArray(chartsAreaQuery.getTypeId(),Long.class);
        List<Long> brandIds = JSON.parseArray(chartsAreaQuery.getBrandId(),Long.class);
        map.put("hospitalIds" ,hospitalIds);
        map.put("levelIds" ,hospitalLevelIds);
        map.put("riskIds" ,riskIds);
        map.put("typeIds",typeIds);
        map.put("brandIds" ,brandIds);
        map.put("modelName", chartsAreaQuery.getModelName());
        map.put("maintainerId", chartsAreaQuery.getMaintainerId());
        map.put("enableYearStart" , chartsAreaQuery.getEnableYearStart());
        map.put("enableYearEnd" , chartsAreaQuery.getEnableYearEnd());
        map.put("ageLimitStart" , chartsAreaQuery.getAgeLimitStart());
        map.put("ageLimitEnd" , chartsAreaQuery.getAgeLimitEnd());
        map.put("maintainSize", chartsAreaQuery.getMaintainSize()); //设置维修大小参数
        if("0".equals(chartsAreaQuery.getPriceStart())){
            chartsAreaQuery.setPriceStart(null);
        }
        map.put("priceStart" , chartsAreaQuery.getPriceStart());
        map.put("priceEnd" , chartsAreaQuery.getPriceEnd());
        map.put("areaId",areaId);
        map.put("queryMax", chartsAreaQuery.getQueryMax());
        map.put("queryMin", chartsAreaQuery.getQueryMin());
        Integer paramYear = (chartsAreaQuery.getYear() == null) ? null : Integer.valueOf(chartsAreaQuery.getYear().replaceAll("\"",""));
        Integer paramMonth = (chartsAreaQuery.getMonthId() == null) ? null :Integer.valueOf(chartsAreaQuery.getMonthId().replaceAll("\"",""));
        dateProcess(paramYear,paramMonth,map);

        return map;
    }


    /**
     * @Author: 杨青桦
     * @Description:  处理设置医院报表sql参数
     * @Date: 2017/8/15 10:32
     * @param chartsHospitalQuery
     * @return
     */
    public static Map<String,Object> getParamMap(Long hospitalId,ChartsHospitalQuery chartsHospitalQuery) throws Exception{
        Map<String,Object> map = new HashMap<>();
        handleString(chartsHospitalQuery);
        if(chartsHospitalQuery.getEnableYearStart() != null){
            chartsHospitalQuery.setEnableYearStart(chartsHospitalQuery.getEnableYearStart()+"-1-1");
        }
        if(chartsHospitalQuery.getEnableYearEnd() != null){
            Integer year = Integer.valueOf(chartsHospitalQuery.getEnableYearEnd())+1;
            chartsHospitalQuery.setEnableYearEnd(year+"-1-1");
        }
        List<Long> departmentIds = JSON.parseArray(chartsHospitalQuery.getDepartmentId(),Long.class);
        List<Long> riskIds = JSON.parseArray(chartsHospitalQuery.getRiskId(),Long.class);
        List<Long> typeIds = JSON.parseArray(chartsHospitalQuery.getTypeId(),Long.class);
        List<Long> brandIds = JSON.parseArray(chartsHospitalQuery.getBrandId(),Long.class);
        map.put("departmentIds" ,departmentIds);
        map.put("riskIds" ,riskIds);
        map.put("typeIds",typeIds);
        if(!CollectionUtils.isEmpty(typeIds) && typeIds.size() == 1){
            if(InitUtil.getFirstTypeIdList().contains(typeIds.get(0))){
                map.put("firstTypeId",typeIds.get(0));
                map.put("typeIds",null);
            }
        }
        map.put("brandIds" ,brandIds);
        map.put("modelName", chartsHospitalQuery.getModelName());
        map.put("maintainerId", chartsHospitalQuery.getMaintainerId());
        map.put("enableYearStart" , chartsHospitalQuery.getEnableYearStart());
        map.put("enableYearEnd" , chartsHospitalQuery.getEnableYearEnd());
        map.put("ageLimitStart" , chartsHospitalQuery.getAgeLimitStart());
        map.put("ageLimitEnd" , chartsHospitalQuery.getAgeLimitEnd());
        if("0".equals(chartsHospitalQuery.getPriceStart())){
            chartsHospitalQuery.setPriceStart(null);
        }
        map.put("priceStart" , chartsHospitalQuery.getPriceStart());
        map.put("priceEnd" , chartsHospitalQuery.getPriceEnd());
        map.put("hospitalId",hospitalId);
        map.put("queryMax", chartsHospitalQuery.getQueryMax());
        map.put("queryMin", chartsHospitalQuery.getQueryMin());
        map.put("queryType", chartsHospitalQuery.getQueryType());
        map.put("maintainSize", chartsHospitalQuery.getMaintainSize()); //设置维修大小参数
        map.put("assetsTag",chartsHospitalQuery.getAssetsTag());
        Integer paramYear = (chartsHospitalQuery.getYear() == null) ? null : Integer.valueOf(chartsHospitalQuery.getYear().replaceAll("\"",""));
        Integer paramMonth = (chartsHospitalQuery.getMonthId() == null) ? null :Integer.valueOf(chartsHospitalQuery.getMonthId().replaceAll("\"",""));
        dateProcess(paramYear,paramMonth,map);

        return map;
    }


    /**
     * @Author: 杨青桦
     * @Description: 日期处理方法
     * @Date: 2017/11/30 11:06
     * @param paramYear 参数年
     * @param paramMonth 参数月
     * @param paramMap  sql参数Map
     */
    public static void dateProcess(Integer paramYear,Integer paramMonth, Map<String,Object> paramMap){
        /**
         * 1.sql查询日期区间使用 >= startDate且<endDate的方式
         *   这样可以查询实时的维护计划，所以需要在当前日期上加一天
         * 2.日期加一天会12月31日时会出现跨年,需要单独处理
         * 3.和去年同期比较，需要考虑闰年及平年,对二月要单独处理
         * 4.传/不传 年份时的处理
         * 5.传/不传 月份时的处理
         */

        //设置今年去年的界限
        Calendar a=Calendar.getInstance();                    //获取日历
        int year = a.get(Calendar.YEAR);                      //获取当前年份
        int month = a.get(Calendar.MONTH)+1;                  //获取当前月份
        int day = a.get(Calendar.DAY_OF_MONTH);               //获取当前月份日期

        a.add(Calendar.DAY_OF_MONTH,1);                       //获取当前日期加一天
        int addOneDayYear = a.get(Calendar.YEAR);             //加一天的年份
        int addOneDayMonth = a.get(Calendar.MONTH)+1;         //加一天的月份
        int addOneDayDay = a.get(Calendar.DAY_OF_MONTH);      //加一天的月份日期

        int curYearNum;                                       //今年年份sql参数
        String thisYearStart;                                 //今年起始时间
        String thisYearEnd;                                   //今年终止时间
        String lastYearStart;                                 //去年起始时间
        String lastYearEnd;                                   //去年终止时间
        String nextYear;                                      //年限指数计算年份
        StringBuilder sb = new StringBuilder();

        //1.传年份
        if(paramYear != null){
            curYearNum = Integer.valueOf(paramYear);          //如果传了当前年份,即为今年年份参数
        }else {
            curYearNum = year;                                //否则即为当前年份
        }
        paramMap.put("curYear",curYearNum);                   //获取当前年份，为月份报表获取当前年份

        if(curYearNum == year){
            nextYear = sb.append(addOneDayYear).append("-").append(addOneDayMonth).append("-").append(addOneDayDay).toString();
        }else{
            nextYear = sb.append(curYearNum + 1).append("-1-1").toString();
        }
        paramMap.put("nextYear",getSqlDate(nextYear));
        sb.setLength(0);

        //2.传月份
        //(1)今年起始时间
        if(paramMonth == null){
            thisYearStart = sb.append(curYearNum).append("-1-1").toString();
        }else{
            thisYearStart = sb.append(curYearNum).append("-").append(paramMonth).append("-1").toString();
        }
        paramMap.put("thisYearStart",getSqlDate(thisYearStart));
        sb.setLength(0);

        //(2)今年终止时间
        if(paramMonth == null){
            //如果参数今年为当前年
            if(curYearNum == year){
                //即为当前日期加一天
                thisYearEnd = sb.append(addOneDayYear).append("-").append(addOneDayMonth).append("-").append(addOneDayDay).toString();
            }else {
                //即为参数今年的第一天
                thisYearEnd = sb.append(curYearNum + 1).append("-1-1").toString();
            }
        }else{
            //参数年份为当前年且参数月份为当前月
            if(curYearNum == year && paramMonth == month){
                //即为当前日期加一天
                thisYearEnd = sb.append(addOneDayYear).append("-").append(addOneDayMonth).append("-").append(addOneDayDay).toString();
            }else if(paramMonth == 12){ //判断月份是否为12月,月份查看
                //即为第二年的第一天
                thisYearEnd = sb.append(curYearNum + 1).append("-1-1").toString();
            }else{
                //即为下一个月的第一天
                thisYearEnd = sb.append(curYearNum).append("-").append(paramMonth + 1).append("-1").toString();
            }
        }
        paramMap.put("thisYearEnd",getSqlDate(thisYearEnd));
        sb.setLength(0);


        //(3)去年开始时间
        if(paramMonth == null){
            //参数年前一年的第一天
            lastYearStart = sb.append(curYearNum-1).append("-1-1").toString();
        }else{
            //参数年前一年的指定月份的第一天
            lastYearStart = sb.append(curYearNum-1).append("-").append(paramMonth).append("-1").toString();
        }
        paramMap.put("lastYearStart",getSqlDate(lastYearStart));
        sb.setLength(0);

        //(4)去年结束时间
        if(paramMonth == null){
            //如果参数年为当前年份
            if(curYearNum == year){
                //对二月份做特殊处理，误差为1天，闰年平年一天的差距忽略
                if(month == 2 && day > 27){
                    //即为去年3月1日
                    lastYearEnd = sb.append(curYearNum-1).append("-3-1").toString();
                }else {
                    //即为去年的当前日期加一天
                    lastYearEnd = sb.append(addOneDayYear-1).append("-").append(addOneDayMonth).append("-").append(addOneDayDay).toString();
                }

            }else {
                //即为参数今年的第一天
                lastYearEnd = sb.append(curYearNum).append("-1-1").toString();
            }
        }else{
            //参数年份为当前年且参数月份为当前月
            if(curYearNum == year && paramMonth == month){
                //参数月为二月份，且日期为28号以上
                if(paramMonth == 2 && day > 27){
                    //即为去年3月1日
                    lastYearEnd = sb.append(curYearNum-1).append("-3-1").toString();
                }else if(paramMonth == 12 && day == 31){ //参数为12月且为最后一天
                    //即为参数今年的第一天
                    lastYearEnd = sb.append(curYearNum).append("-1-1").toString();
                }else {
                    //即为去年的当前日期加一天
                    lastYearEnd = sb.append(addOneDayYear-1).append("-").append(addOneDayMonth).append("-").append(addOneDayDay).toString();
                }
            }else {
                //对12月份处理
                if(paramMonth == 12){
                    //即为参数今年的第一天
                    lastYearEnd = sb.append(curYearNum).append("-1-1").toString();
                }else{
                    lastYearEnd = sb.append(curYearNum-1).append("-").append(paramMonth+1).append("-1").toString();
                }
            }
        }
        paramMap.put("lastYearEnd",getSqlDate(lastYearEnd));
        sb.setLength(0);

        //当前日期
        paramMap.put("calendar",sb.append(year).append("-").append(month).append("-").append(day).toString());

    }


    /**
     * @Author: 杨青桦
     * @Description:   sql日期参数拼接
     * @Date: 2018/1/5 16:24
     * @param date
     * @return
     */
    private static String getSqlDate(String date){
        StringBuffer sb = new StringBuffer();
        sb.append("'").append(date).append("'");
        return sb.toString();
    }


    /**
     * 添加拼音首字母方便查询
     * @param list
     * @return
     */
    public static List<ChartsSearchView> getPinYin(List<ChartsSearchView> list){
        for(ChartsSearchView obj:list){
            obj.setName(obj.getName()+"["+ChineseToEnglish.getPinYinHeadChar(obj.getName())+"]");
        }
        return list;
    }


    /** 
     * @Author: 杨青桦
     * @Description: 参数空字符串转换为空
     * @Date: 2017/7/19 15:18
     * @param object
     * @return
     */
    public static Object handleString(Object object)throws Exception{
        Class clazz = object.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for(int i=0;i<fields.length;i++) {
            Method get = getGetMethod(clazz, fields[i].getName());
            Method set = getSetMethod(clazz, fields[i].getName());
            Object resultObject = get.invoke(object);
            if(resultObject == null || "undefined".equals(resultObject.toString()) || "".equals(resultObject.toString())){
                resultObject = null;
                set.invoke(object,resultObject);
            }
        }
        return object;
    }

    /**
     * 获取set方法
     * @param clazz
     * @param fieldName
     * @return
     * @throws Exception
     */
    public static Method getSetMethod(Class clazz, String fieldName) throws Exception{
        Field field = clazz.getDeclaredField(fieldName);
        StringBuffer sb = new StringBuffer();
        sb.append("set");
        sb.append(fieldName.substring(0, 1).toUpperCase());
        sb.append(fieldName.substring(1));
        return clazz.getMethod(sb.toString(),field.getType());
    }


    /**
     * 获取get方法
     * @param clazz
     * @param fieldName
     * @return
     * @throws Exception
     */
    public static Method getGetMethod(Class clazz, String fieldName) throws Exception{
        StringBuffer sb = new StringBuffer();
        sb.append("get");
        sb.append(fieldName.substring(0, 1).toUpperCase());
        sb.append(fieldName.substring(1));
        return clazz.getMethod(sb.toString());
    }



    /**
     * 返回分页数据
     * @param list
     * @param chartsHospitalQuery
     * @return
     * @throws Exception
     */
    public static List listForPage(List list, ChartsHospitalQuery chartsHospitalQuery) throws Exception{
        if(list.size() == 0){
            return list;
        }
        List returnList = new ArrayList<>();
        String sortord = chartsHospitalQuery.getSortord();
        if(sortord == null || "".equals(sortord)){
            chartsHospitalQuery.setSort("id");
            chartsHospitalQuery.setPage(new Page(0,10000));
            chartsHospitalQuery.setSortord("desc");
        }
        int start = chartsHospitalQuery.getPage().getStart();
        int limit = chartsHospitalQuery.getPage().getLimit();
        int max;
        if(start+limit > list.size()){
            max = list.size();
        }else{
            max = start + limit;
        }
        Method method = getGetMethod(list.get(0).getClass(), chartsHospitalQuery.getSort());
        String returnTypeName = method.getReturnType().getName();
        if("double".equals(returnTypeName) || "java.lang.Double".equals(returnTypeName)){
            for(int i=0;i<list.size();i++){
                for(int j=0;j<list.size()-i-1;j++){
                    Double result1 = (Double)method.invoke(list.get(j));
                    Double result2 = (Double)method.invoke(list.get(j+1));
                    if("asc".equals(sortord)){
                        if(result1.doubleValue() > result2.doubleValue()){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }else{
                        if(result1.doubleValue() < result2.doubleValue()){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }
                }
            }
        }else if("java.lang.Long".equals(returnTypeName)){
            for(int i=0;i<list.size();i++){
                for(int j=0;j<list.size()-i-1;j++){
                    Long result1 = (Long)method.invoke(list.get(j));
                    Long result2 = (Long)method.invoke(list.get(j+1));
                    if("asc".equals(sortord)){
                        if(result1.longValue() > result2.longValue()){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }else{
                        if(result1.longValue() < result2.longValue()){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }
                }
            }
        }else if("java.lang.String".equals(returnTypeName)){
            for(int i=0;i<list.size();i++){
                for(int j=0;j<list.size()-i-1;j++){
                    String result1 = (String)method.invoke(list.get(j));
                    String result2 = (String)method.invoke(list.get(j+1));
                    if("asc".equals(sortord)){
                        if(result1.compareTo(result2) >= 0){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }else{
                        if(result1.compareTo(result2) < 0 ){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }
                }
            }

        }else {
            for(int i=0;i<list.size();i++){
                for(int j=0;j<list.size()-i-1;j++){
                    Integer result1 = (Integer)method.invoke(list.get(j));
                    Integer result2 = (Integer)method.invoke(list.get(j+1));
                    if("asc".equals(sortord)){
                        if(result1.intValue() > result2.intValue()){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }else{
                        if(result1.intValue() < result2.intValue()){
                            Object temp = list.get(j);
                            list.set(j,list.get(j+1));
                            list.set(j+1,temp);
                        }
                    }
                }
            }

        }

        for(int i = start;i<max;i++){
            returnList.add(list.get(i));
        }
        return returnList;
    }

    /** 
     * @Author: 杨青桦
     * @Description:  不排序的分页
     * @Date: 2017/10/17 15:28
     * @param list
     * @param chartsHospitalQuery
     * @return
     */
    public static List listForPageWithOutOrder(List list,ChartsHospitalQuery chartsHospitalQuery){
        List returnList = new ArrayList<>();
        Page page = chartsHospitalQuery.getPage();
        if(page == null){
            chartsHospitalQuery.setPage(new Page(0,10000));
        }
        int start = chartsHospitalQuery.getPage().getStart();
        int limit = chartsHospitalQuery.getPage().getLimit();
        int max;
        if(start+limit > list.size()){
            max = list.size();
        }else{
            max = start + limit;
        }
        for(int i = start;i<max;i++){
            returnList.add(list.get(i));
        }
        return returnList;
    }

}
